#include<iostream> 
#include<algorithm>
#include<vector>
#include<cstring> 
using namespace std;
class Solution {
public:
    int matrixScore(vector<vector<int>>& A) {
    	int len = 0;
		for(int i = 0; i < A.size(); i++, len++){
			if(!A[i][0])for(int j = 0; j < A[i].size(); j++)A[i][j] ^= 1; 
		}
		int num[20];
		memset(num, 0, sizeof(num));	
		for(int i = 0; i < A[0].size(); i++){
			for(int j = 0; j < A.size(); j++){
				if(A[j][i])num[i]++;
			}
		}
		for(int i = 0; i < A[0].size(); i++){
			if(num[i] <= len / 2)for(int j = 0; j < A.size(); j++)A[j][i] ^= 1;
		}		
		int ans = 0;
		for(int i = 0; i < A.size(); i++){
			int quan = 1;
			for(int j = A[i].size() - 1; j >= 0; j--){
				if(A[i][j]){
					ans += quan;
				}
				quan <<= 1;
			}
		}
		return ans;
    }
};

int main(){
	vector<vector<int>> v = {{0,0,1,1},{1,0,1,0},{1,1,0,0}};
	Solution a;
	cout << a.matrixScore(v);
	return 0;
}
